package com.amqr.mediaplayer.activity;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.SurfaceView;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.amqr.mediaplayer.R;
import com.amqr.mediaplayer.widget.AMQRVideoPlayerController;

/**
 * User: LJM
 * Date&Time: 2017-06-26 & 20:23
 * Describe: Describe Text
 */
public class TimePlayVideoActivity extends AppCompatActivity {

    private static final String TAG = "MEDIA_TEST";
    private FrameLayout playerContainer;
    private SurfaceView surfaceView;

    private String url1 = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4";
    //private String url1 = "http://96.9.67.144:81/gchat/8613413422231/1493172571591.mp4";


    private AMQRVideoPlayerController mAmqrVideoPlayerController;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_video);

        playerContainer = (FrameLayout) findViewById(R.id.playerContainer);
        surfaceView = (SurfaceView) this.findViewById(R.id.surfaceView);

        // 添加视频控制层
        mAmqrVideoPlayerController = new AMQRVideoPlayerController(TimePlayVideoActivity.this,surfaceView,url1);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        playerContainer.addView(mAmqrVideoPlayerController,params);

        // 配置视频控制层
        mAmqrVideoPlayerController.setFullAllScreen(false);
        mAmqrVideoPlayerController.setAutoPlay(false);
        mAmqrVideoPlayerController.setLoop(false);

        // 视屏控制层操作回调
        mAmqrVideoPlayerController.setControllerOperate(mIControllerOperate);

    }


    AMQRVideoPlayerController.IControllerOperate mIControllerOperate = new AMQRVideoPlayerController.IControllerOperate() {
        @Override
        public void centerStart() {
            mAmqrVideoPlayerController.mediaPlay();
        }

        @Override
        public void pauseOrRestart() {
            mAmqrVideoPlayerController.mediaPauseOrRestart();
        }

        @Override
        public void rePlay() {
            mAmqrVideoPlayerController.rePlayer();
        }
    };

    @Override
    protected void onPause() {
        mAmqrVideoPlayerController.mediaPauseOrRestart();
        super.onPause();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        //mAmqrVideoPlayerController.mediaStop();
    }


}
